home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
misc
/
vuzkern.gz
/
vuzkern
Wrap
Text File
|
1995-09-18
|
3KB
|
94 lines
#!/usr/local/bin/perl
#
# vuzkern
#
# Read compressed kernels and extract their uncompressed binary image
# (or info, version str from it) to the standard output.
# Use it to see into your compressed kernels. I build too many for different
# machines and forget versions and what they include
#
# This is a quick hack: Rather than trying to follow internal structures
# (which change) to spot the point where vmlinux-compressed starts,
# we skip some blocks and search for the gzip-deflated magic.
# This is where the kernel starts (hopefully :).
#
# Copyright (c) 1995 Angelo Haritsis <ah@doc.ic.ac.uk>
#
# DISTRIBUTE FREELY, PROVIDED THE ABOVE COPYRIGHT IS KEPT. NO WARRANTIES.
#
# $Header: /usr/local/bin/RCS/vuzkern,v 1.1 1995/08/22 12:03:12 ah Exp ah $
#
$GzipMagic = "\x1f\x8b\x8"; # deflate
$SkipBlocks=25; # kernel compressed bin is not there
$VersionReadBytes = 50*1024; # bytes2read when seeking for version str
$ZflagOffset=498; # where kernel flags start
$progname = "vuzkern";
$usage = "$progname v1.0: View inside a linux bootable zkernel
usage: $progname [-v | -a | -r] vmlinuz ...
Options:
-v show only the kernel version string (default)
-a raw cat of kernel piped to 'strings -8'
-r raw cat of kernel binary
Examples:
See the version of all your zkernels: $progname /vm* /dev/fd0
Browse ascii strings in a kernel: $progname -a vmlinuz | less
";
$#ARGV >= 0 || die $usage;
$check = 1; # default = kernel version
# process command line options
while ($_ = $ARGV[0], /^-/) {
shift;
last if /^--$/;
/-h|-\?/ && die $usage;
/-v/ && ($check = 1, next);
/-a/ && ($check = 2, next);
/-r/ && ($check = 3, next);
die "$progname: illegal option\n\n$usage";
}
foreach $f (@ARGV) {
print STDERR ">> Kernel: [$f]\n";
open(ZKERN, "$f") || die "Cannot open $f\n";
if ($check != 3) { # show all kernel flags also
seek(ZKERN, $ZflagOffset, 0);
read(ZKERN, $ZFlags, 14);
#syswrite(STDOUT, $ZFlags, 14); exit;
($f_root, $f_sysize, $f_swapdev, $f_ram, $f_vid, $f_rootdev, $f_boot) =
unpack("S7", $ZFlags);
$| = 1;
printf "rflag=%d, rootdev=%04X, swapdev=%04X, ram=%d, vid=%s, size=%d\n",
$f_root, $f_rootdev, $f_swapdev, $f_ram, $f_vid, $f_sysize*16;
}
seek(ZKERN, $SkipBlocks*512, 0);
# slurp the rest in (less than 500k)
$slurp_bytes = 500*1024;
# read less if we need only version
$check == 1 && ( $slurp_bytes = $VersionReadBytes + 10*1024);
$num = read(ZKERN, $Buffer, $slurp_bytes);
# search for the gzip magic
$offset = index($Buffer, $GzipMagic);
# prepare popen cmd
$gzip="gzip -dc 2>/dev/null";
$cmd = "$gzip | strings -8|grep \"Linux ver\"" if ($check == 1);
$cmd = "$gzip | strings -8" if ($check == 2);
$cmd = "$gzip" if ($check == 3);
#print substr($Buffer, $offset); exit;
close(2);
open (KERN, "|$cmd") || die "Cannot open pipe\n";
($check == 1) && print KERN substr($Buffer, $offset, $VersionReadBytes);
($check != 1) && print KERN substr($Buffer, $offset);
close KERN;
close ZKERN;
}